<template>
  <div class="goodPerson">
    <div class="tabbar">
      <div class="icon"><p>人才库</p></div>
      <div class="welcome"></div>
    </div>
    <div class="search">
      <div class="cx">
        <span class="a">筛选查询</span>
      </div>
      <div class="search_type">
        <div>
          姓名：<input type="text" placeholder="输入姓名" v-model="name" />
        </div>
        <div class="sou" @click="search">搜索</div>
      </div>
    </div>
    <div class="addbox">
      <div class="num">数据列表</div>
      <div class="addPerson" @click="headClick">人员导入</div>
    </div>

    <div class="example-pagination-block">
      <div class="example-demonstration">
        <el-table :data="tableData" border style="width: 100%">
          <!-- <el-table-column prop="id" label="人员编号" width="180" /> -->
          <el-table-column prop="name" label="姓名" width="180" />
          <el-table-column prop="job" label="工作" width="180" />
          <el-table-column prop="phone" label="电话" width="180" />
          <el-table-column prop="from" label="信息来源" width="180" />
          <el-table-column prop="status" label="面试反馈" width="180" />
          <el-table-column prop="peopleStatus" label="人员状态" width="180" />
          <el-table-column prop="name" label="操作" width="180">
            <template #default="scope">
              <el-button
                link
                type="primary"
                size="small"
                @click.prevent="editRow(scope.row)"
                >编辑</el-button
              >
              <el-button
                link
                type="primary"
                size="small"
                @click.prevent="deleteRow(scope.row)"
                >删除</el-button
              >
              <el-button
                link
                type="primary"
                size="small"
                @click.prevent="look(scope.row)"
                >查看</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
      <el-pagination
        layout="prev, pager, next"
        :total="100"
        :page-size="10"
        :background="true"
        :default-page-size="10"
      />
    </div>
  </div>
</template>

<script setup>
import { onMounted, ref } from "vue";
import axios from "axios";
import { useRouter } from "vue-router";

//定义响应式数据
var tableData = ref([]);
//定义路由
var router = useRouter();

onMounted(() => {
  axios.get("/api/people/list").then((res) => {
    // console.log(res.data);
    tableData.value = res.data.list;
  });
});
var deleteRow = (row) => {
  axios.post("/api/user/delete", { id: row.id }).then((res) => {
    // console.log(res.data);
    tableData.value = res.data.list;
  });
};

var editRow = (row) => {
  router.push({ path: "/index/changePerson", query: row });
};

var look = (row) => {
  router.push({
    path: "/index/lookPerson",
    query: row,
  });
  // console.log(JSON.stringify(row));
};
var headClick = () => {
  router.push("/index/addPerson");
};
var name = ref("");

var search = () => {
  if (name.value == false) {
    alert("搜索内容不能为空");
  } else {
    router.push("/index/searchPerson" + JSON.stringify(name.value));
  }
};
</script>

<style scoped lang="scss">
.icon {
  width: 100%;
  height: 50px;
  background-color: rgb(242, 242, 242);
  line-height: 50px;
}
.icon p {
  margin-left: 50px;
}
.tabbar {
  width: 100%;
  height: 50px;
  border-bottom: 1px solid #ccc;
  padding: 0;
}
.addPerson {
  width: 80px;
  text-align: center;
  line-height: 40px;
  height: 40px;
  margin-right: 160px;
  background-color: #fff;
  /* border-radius: 8px; */
  cursor: pointer;
  color: #63b9be;
}
.addPerson:hover {
  background-color: #63b9be;
  color: #fff;
}
.addbox {
  height: 60px;
  background-color: rgba(242, 242, 242, 1);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.search {
  width: 100%;
  height: 120px;
  background: #fff;
  margin-bottom: 50px;
  font-size: 14px;
  margin-left: 100px;
  .cx {
    height: 50px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    line-height: 50px;
    .a {
      margin-left: 10px;
    }
    .b {
      width: 70px;
      height: 50px;
      background: #f2f2f2;
      text-align: center;
      cursor: pointer;
      color: #63c8e0;
    }
  }
  .search_type {
    display: flex;
    align-items: center;
    background: white;
    height: 70px;
    // border-bottom: 1px solid #e4e4e4;
    // margin-left: 100px;
    background-color: #fff;
    div {
      margin-left: 10px;
      input {
        width: 100px;
        height: 40px;
        border: none;
        outline: none;
        border: 1px solid #e4e4e4;
      }
    }
  }
}
.sou {
  margin-left: 80px;
  text-align: center;
  line-height: 30px;
  width: 60px;
  height: 30px;
  background-color: #f5f5f5;
  border-radius: 10px;
  cursor: pointer;
}
.sou:hover {
  background-color: #63b9be;
  color: #fff;
}
.example-pagination-block {
  margin-left: 50px;
}
.num {
  margin-left: 50px;
}
</style>